﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Odyssey.Linq;
using SunTzu.Web;
using System.IO;
using Rea.Web.Models;
using SunTzu.Core.Data;
using Odyssey.Web.Models;

namespace Odyssey.Web.Controllers
{
    public class MediaController : FrontBaseController
    {
        public ActionResult Apply()
        {
            ViewData.Model = new form_media();
            BindMasterViewData(1);
            return View();
        }

        [HttpPost]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult CreateMedia()
        {
            form_media apply = new form_media();
            HTMLHelper.BindModel(apply);
            if (apply.SaveOrUpdate())
            {
                SetMessage("提交成功！请等待审核");
            }

            return RedirectToAction("Apply");
        }

        public ActionResult Detail(int id)
        {
            form_media entity = db.form_medias.FirstOrDefault(c => c.Id == id);
            ViewData.Model = entity ?? new form_media();
            BindMasterViewData(1);
            return View();
        }

        public ActionResult List(int? page)
        {
            PagedList<form_media> mediaList = null;
            //if (subcategory.HasValue)
            //{
            //var sub = subcategory.ToString();
            mediaList = db.form_medias
                .Where(c => c.State == 1)
                .ToPagedList(page.GetValueOrDefault());

            //}
            ViewBag.SubClassName = "合作媒体";
            ViewBag.Media = mediaList ?? new List<form_media>().ToPagedList(page.GetValueOrDefault());
            BindMasterViewData(1);
            return View();
        }
    }
}
